<template>
  <view v-if="bannerList && bannerList.length > 0">
    <u-swiper
      :list="bannerList"
      mode="dot"
      :height="260"
      :border-radius="16"
      :interval="5000"
      @click="handleBanner"></u-swiper>
  </view>
</template>

<script>
  import { posterList } from '@/api/applet';
  export default {
    props: {
      type: {
        type: String,
        default: '2'
      }
    },
    data() {
      return {
        bannerList: [],
      }
    },
    mounted() {
      this.getFindAllBannerListByType();
    },
    methods: {
      // 获取海报
			getFindAllBannerListByType() {
				posterList({
					type: this.type
				}).then(result => {
					if (result && result.code === 200) {
            let data = result.data
            let arr = []
            data.map(i=>{
              if(i.active_type == 1||i.active_type == 2||i.active_type == 3){
                arr.push(i)
              }
            })
            this.bannerList = arr
          }
				})
			},

      // 点击轮播图
      handleBanner(val) {
        const bannerInfo = this.bannerList[val];
        // 轮播跳转类型0 没有操作 1 tab页，2内页 3 url 4 跳转小程序 5 活动
        if (bannerInfo.active_type === 1) {
          uni.switchTab({
            url: bannerInfo.content
          })
        } else if (bannerInfo.active_type === 2) {
          uni.navigateTo({
            url: bannerInfo.content
          })
        } else if (bannerInfo.active_type === 3) {
          location.href = bannerInfo.content;
        } else if (bannerInfo.active_type === 4) {
          uni.navigateToMiniProgram({
            appId: bannerInfo.appid,
            path: bannerInfo.content,
            success(res) {
              // 打开成功
            }
          })
        }
      },
    }
  }
</script>

<style lang="scss" scoped>
  .index-container{
    padding: 32rpx;
  }
</style>
